{% from "includes/forms.html" import tip %}

{% macro status_and_tip(addon) %}
  {% set url = addon.get_dev_url('versions') %}
  {% if addon.status != amo.STATUS_DISABLED and addon.disabled_by_user %}
    {% set status_text = _('Invisible') %}
    {% set tooltip_text = status_tips['invisible'] %}
  {% else %}
    {% set promoted_groups = addon.promoted_groups() %}
    {% if addon.status == amo.STATUS_APPROVED and promoted_groups.badged|python_any %}
      {% set status_text = _('Approved and %s' % promoted_groups.filter(badged=True).name) %}
    {% else %}
      {% set status_text = addon.get_status_display() %}
    {% endif %}
    {% set tooltip_text = status_tips[addon.status] %}
  {% endif %}
  <a href="{{ url }}">
    <span class="{{ status_class(addon) }}"><b>{{ status_text }}</b></span>
  </a>
  <span class="tip tooltip" title="{{ tooltip_text }}">?</span>
{% endmacro %}

{% set status_tips = {
    amo.STATUS_NULL: _('Please complete your add-on by adding a version or missing metadata.'),
    amo.STATUS_NOMINATED: _("You will receive an email when the review is complete. Until "
                            "then, your add-on is not listed in our gallery but can be "
                            "accessed directly from its details page. "),
    amo.STATUS_APPROVED: _("Your add-on is displayed in our gallery and users are "
                         "receiving automatic updates."),
    amo.STATUS_DISABLED: _("Your add-on was disabled by a site administrator and is no "
                           "longer shown in our gallery."),
    amo.STATUS_DELETED: '',
    'invisible': _("Your add-on won't be included in search results, and its "
                   "listing page will indicate you disabled it. New version "
                   "submissions for listing won't be accepted in this state."),
} %}

{% if sorting == 'created' %}
  <li class="date-created">
    <strong>{{ _('Created:') }}</strong>
      {# L10n: {0} is a date. dennis-ignore: E201,E202,W202 #}
      {{ addon.created|date }}
  </li>
{% else %}
  <li class="date-updated">
    <strong>{{ _('Last Updated:') }}</strong>
      {# L10n: {0} is a date. dennis-ignore: E201,E202,W202 #}
      {{ addon.last_updated|date }}
  </li>
{% endif %}

{% if addon.has_listed_versions() %}
    {% if addon.has_unlisted_versions() %}
      <li class="distribution-tag-listed">
        <span class="distribution-tag-listed tooltip"
              title="{{ _('Listed on this site after passing code review. Automatic updates are handled by this site') }}"
              >AMO</span>
      </li>
    {% endif %}
    <li class="addon-listed-status">
      <strong>
        {{ _('Status:') }} {{ status_and_tip(addon) }}
      </strong>
    </li>

    {% if addon.current_version %}
      <li>
        <strong>{{ _('Listed Version:') }}</strong>
        <a href="{{ addon.current_version.get_url_path() }}">{{ addon.current_version.version }}</a>
        <span class="tip tooltip" title="{{ _('This is the version of your add-on that will '
                                              'be installed if someone clicks the Install '
                                              'button on addons.mozilla.org') }}">?</span>
      </li>
    {% endif %}

    {% set latest_listed_version = addon.find_latest_version(channel=amo.CHANNEL_LISTED) %}
    {% if latest_listed_version and latest_listed_version != addon.current_version %}
      <li>
        <strong>{{ _('Next Listed Version:') }}</strong>
        {{ latest_listed_version.version }}
        <span class="tip tooltip" title="{{ _('This is the newest uploaded version, however it isn’t live on the site yet') }}">?</span>
      </li>
    {% endif %}
{% endif %}

{% if addon.status == amo.STATUS_DISABLED and not addon.has_listed_versions() %}
    <li>
        <strong>
          {{ _('Status:') }} {{ status_and_tip(addon) }}
        </strong>
      </li>
{% endif %}

{% set latest_unlisted_version=addon.find_latest_version(channel=amo.CHANNEL_UNLISTED) %}
{% if latest_unlisted_version %}
    {% if addon.has_listed_versions() %}
      <li class="distribution-tag-unlisted">
          <span class="distribution-tag-unlisted tooltip"
                title="{{ _('Signed for self-distribution. Updates are handled by you.') }}"
                >Self</span>
      </li>
    {% endif %}

    <li>
      <strong>{{ _('Latest Version:') }}</strong>
      {{ latest_unlisted_version.version }}
      <span class="tip tooltip" title="{{ _('This is the newest uploaded unlisted version') }}">?</span>
    </li>
{% endif %}
